<?php

namespace app\common\model\record;

use think\Model;

class Money extends Model
{
    // 表名
    protected $name = 'record_money';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    
    // 追加属性
    protected $append = [
        'on_time_text',
        'payed_text',
        'update_time_text'
    ];
    

    
    public function getPayedList()
    {
        return ['1' => __('Payed 1'),'2' => __('Payed 2')];
    }     


    public function getOnTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['on_time']) ? $data['on_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getPayedTextAttr($value, $data)
    {        
        $value = $value ? $value : (isset($data['payed']) ? $data['payed'] : '');
        $list = $this->getPayedList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getUpdateTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['update_time']) ? $data['update_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setOnTimeAttr($value)
    {
        return $value && !is_numeric($value) ? strtotime($value) : $value;
    }

    protected function setUpdateTimeAttr($value)
    {
        return $value && !is_numeric($value) ? strtotime($value) : $value;
    }


    public function order()
    {
        return $this->hasOne('app\admin\model\shop\Order',"order_id","order_id");
    }




}
